package com.gitee.cui.netty.handler;

import com.gitee.cui.util.Logger;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

import java.net.SocketAddress;

/**
 * 出站业务处理类
 * [main|OutboundHandler.handlerAdded] |>  handlerAdded() 被调用
 * [main|OutboundHandler.read] |>  read() 被调用
 * [main|OutboundHandler.write] |>  write() 被调用
 * [main|OutboundHandler.flush] |>  flush() 被调用
 * write is finished
 * [main|OutboundHandler.close] |>  close() 被调用
 * [main|OutboundHandler.handlerRemoved] |>  handlerRemoved() 被调用
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/21 17:11
 **/
public class OutboundHandler extends ChannelOutboundHandlerAdapter {
    @Override
    public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception {
        Logger.info("bind() 被调用");
        super.bind(ctx, localAddress, promise);
    }

    @Override
    public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
        Logger.info("connect() 被调用");
        super.connect(ctx, remoteAddress, localAddress, promise);
    }

    @Override
    public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
        Logger.info("disconnect() 被调用");
        super.disconnect(ctx, promise);
    }

    @Override
    public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
        Logger.info("close() 被调用");
        super.close(ctx, promise);
    }

    @Override
    public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
        Logger.info("bind() 被调用");
        super.deregister(ctx, promise);
    }

    @Override
    public void read(ChannelHandlerContext ctx) throws Exception {
        Logger.info("read() 被调用");
        super.read(ctx);
    }

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        Logger.info("write() 被调用");
        super.write(ctx, msg, promise);
    }

    @Override
    public void flush(ChannelHandlerContext ctx) throws Exception {
        Logger.info("flush() 被调用");
        super.flush(ctx);
    }

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
        Logger.info("handlerAdded() 被调用");
        super.handlerAdded(ctx);
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
        Logger.info("handlerRemoved() 被调用");
        super.handlerRemoved(ctx);
    }
}
